using mvc.Models;
using System;
using Microsoft.EntityFrameworkCore;
using mvc.Db;
using System.Linq;
namespace mvc.IR
{
    public class ERe<T> : IRe<T> where T : BaseModel
    {
        private readonly Dbcon _db;
        private readonly DbSet<T> _t;

        public IQueryable<T> table
        {
            get
            {
                return _t.AsQueryable();
            }
        }


        public ERe()
        {
            _db = new Dbcon();
            _t = _db.Set<T>();
        }
        public void Delete(int id)
        {
            var entity = _t.Where(x=>x.Id==id).FirstOrDefault();
            entity.IsDelete=true;
            _t.Update(entity);
            _db.SaveChanges();
        }

        public void Insert(T entity)
        {
           entity.IsDelete=false;
           entity.Createtime=System.DateTime.Now;
           _t.Add(entity);
           _db.SaveChanges();
        }

        public void Update(T entity)
        {
           _t.Update(entity);
           _db.SaveChanges();
        }
    }
}